package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.AttendStatus;
import org.jsola.hr.dto.AttendanceDedAddDTO;
import org.jsola.hr.dto.AttendanceDedUpdateDTO;
import org.jsola.hr.entity.AttendanceDedDO;
import org.jsola.hr.query.AttendanceDedQuery;
import org.jsola.hr.service.IAttendanceDedService;
import org.jsola.hr.vo.AttendanceDedVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendanceDedTestHelper extends BaseTestHelper {

    @Autowired
    private IAttendanceDedService attendanceDedService;

    /**
     * 生成add测试数据
     * @return AttendanceDedAddDTO
     */
    public AttendanceDedAddDTO getAttendanceDedAddDTO(){
        AttendanceDedAddDTO attendanceDedAddDTO = new AttendanceDedAddDTO();
        attendanceDedAddDTO.setProgrammeId(getRandomValue("varchar",32));
        attendanceDedAddDTO.setDedType(AttendStatus.MISS_CARD.getValue().toString());
        attendanceDedAddDTO.setName(getRandomValue("varchar",255));
        attendanceDedAddDTO.setType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendanceDedAddDTO.setAmountMinute(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceDedAddDTO.setAmountAbsenteeism(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceDedAddDTO.setOverallRange(getRandomValue("varchar",255));
        attendanceDedAddDTO.setStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        attendanceDedAddDTO.setCompanyId(getRandomValue("varchar",32));
        return attendanceDedAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendanceDedUpdateDTO
     */
    public AttendanceDedUpdateDTO getAttendanceDedUpdateDTO(AttendanceDedVO attendanceDedVO){
        return attendanceDedService.selectDOById(attendanceDedVO.getId(), SITE_ID).to(AttendanceDedUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendanceDedQuery
     */
    public AttendanceDedQuery getAttendanceDedQuery() {
        AttendanceDedQuery attendanceDedQuery = new AttendanceDedQuery();
        List<AttendanceDedDO> attendanceDedDOList = attendanceDedService.list(new AttendanceDedDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendanceDedDOList)) {
            AttendanceDedDO attendanceDedDO = attendanceDedDOList.get(0);
            attendanceDedQuery = attendanceDedDO.to(AttendanceDedQuery.class);
            if (attendanceDedDO.getGmtCreate() != null) {
                attendanceDedQuery.setGmtCreateStart(DateKit.getBeforeDay(attendanceDedDO.getGmtCreate(),-1));
                attendanceDedQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendanceDedDO.getGmtCreate(),1));
            }
            if (attendanceDedDO.getGmtModified() != null) {
                attendanceDedQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendanceDedDO.getGmtModified(),-1));
                attendanceDedQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendanceDedDO.getGmtModified(),1));
            }
        }
        return attendanceDedQuery;
    }

    /**
     * 保存示例
     * @return AttendanceDedVO
     */
    public AttendanceDedVO saveAttendanceDedExample(){
        AttendanceDedAddDTO addDTO = this.getAttendanceDedAddDTO();
        AttendanceDedVO attendanceDedVO = attendanceDedService.save(addDTO,buildTokenUser());
        return attendanceDedVO;
    }


}
